package cn.darkhorse.mesadmin.controller.ticket;


import cn.darkhorse.ticket.production.dto.TicketProductionPlanInfoDTO;
import cn.darkhorse.ticket.production.pojo.TicketProductionPlanProductInfo;
import cn.darkhorse.ticket.production.service.TicketProductionPlanInfoService;
import cn.darkhorse.ticket.production.service.TicketProductionPlanProductInfoService;
import cn.darkhorse.ticket.production.vo.TicketProductionPlanInfoVO;
import cn.darkhorse.ticket.production.vo.TicketProductionPlanInfoViewVO;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 生产计划信息 前端控制器
 * </p>
 *
 * @author maoguanjun
 * @since 2024-01-19
 */
@RestController
@RequestMapping("/ticketproduction/ticketProductionPlanInfo")
public class TicketProductionPlanInfoController extends BaseController {
    @Resource
    private TicketProductionPlanInfoService ticketProductionPlanInfoService;

    /**
     * 列表
     * @param dto
     * @return
     */
    @RequestMapping("/list")
    public TableDataInfo list(TicketProductionPlanInfoDTO dto){
        startPage();
        return ticketProductionPlanInfoService.listAll(dto);
    }

    /**
     * 保存
     * @param info
     * @return
     */
    @RequestMapping("/save")
    public AjaxResult save(@Validated @RequestBody TicketProductionPlanInfoVO info){
        boolean result=ticketProductionPlanInfoService.savePlan(info);
        return AjaxResult.success(result);
    }

    /**
     * 查看
     * @param dataId
     * @return
     */
    @RequestMapping("/view")
    public AjaxResult view(Long dataId){
        if(null==dataId){
            return  AjaxResult.error("缺失参数！");
        }
        TicketProductionPlanInfoViewVO result=ticketProductionPlanInfoService.view(dataId);
        return AjaxResult.success(result);
    }

    /**
     * 关闭
     * @param dataId
     * @return
     */
    @RequestMapping("/close")
    public AjaxResult close(Long dataId){
        if(null==dataId){
            return  AjaxResult.error("缺失参数！");
        }
        boolean result=ticketProductionPlanInfoService.close(dataId);
        return AjaxResult.success(result);
    }

    /**
     * 创建工单
     * @param dataId 计划Id
     * @return
     */
    @RequestMapping("/create-ticket")
    public AjaxResult createTicket(Long dataId){
        if(null==dataId){
            return  AjaxResult.error("缺失参数！");
        }
        String result=ticketProductionPlanInfoService.createTicket(dataId,null);
        return AjaxResult.success(result);
    }

    /**
     * 创建工单
     * @param dataId 计划Id
     * @param dataDetailId 产品明细Id
     * @return
     */
    @RequestMapping("/create-ticket-detail")
    public AjaxResult createTicketDetail(Long dataId,Long dataDetailId){
        if(null==dataId||null==dataDetailId){
            return  AjaxResult.error("缺失参数！");
        }
        String result=ticketProductionPlanInfoService.createTicket(dataId,dataDetailId);
        return AjaxResult.success(result);
    }

    /**
     * 获取未生成工单产品
     * @param dataId 计划Id
     * @return
     */
    @RequestMapping("/get-product")
    public AjaxResult getProduct(Long dataId){
        if(null==dataId){
            return  AjaxResult.error("缺失参数！");
        }
        List<TicketProductionPlanProductInfo> list =ticketProductionPlanInfoService.getProduct(dataId);
        return AjaxResult.success(list);
    }
}

